<!--
 * @Author: WuFeng <763467339@qq.com>
 * @Date: 2022-11-29 21:28:54
 * @LastEditTime: 2023-04-27 16:35:06
 * @LastEditors: WuFeng <763467339@qq.com>
 * @Description: 移动
 * @FilePath: \vue3-element-plus-web\src\views\SysManage\Resource\components\Drawer\move.vue
 * Copyright 版权声明
-->
<template>
  <div class="">
    <el-form
      :rules="rules"
      ref="dataForm"
      :model="temp"
      label-width="140px"
      style='width:100%;'
    >

      <el-form-item label="当前资源：">
        {{pageParams.name}}
      </el-form-item>

      <el-form-item label="父资源：" prop="parentIdArr">
        <el-cascader
          :options="treeList"
          v-model="temp.parentIdArr"
          :props="parentIdProps"
          @change="handleChange"
          clearable
          placeholder="请选择所属父资源"
        />
      </el-form-item>

    </el-form>
  </div>
</template>

<script>
import { mapGetters } from 'vuex'
import { getTree as getList } from '@/api/SysManage/resource'

export default {
  name: 'Create',
  computed: {
    ...mapGetters([
      'drawerCurrent'
    ]),
    drawerType: function() {
      return this.drawerCurrent.drawerType
    }
  },
  components: {
  },
  data() {
    return {
      treeList: [],
      parentIdProps: {
        value: 'id',
        label: 'name',
        checkStrictly: true
        // lazy: true,
        // async lazyLoad(node, resolve) {
        //   const { level } = node
        //   let parentId = 0
        //   if (level > 0) {
        //     parentId = node.data.id
        //   }

        //   const res = await getList({
        //     current: 1,
        //     size: 9999,
        //     parentId
        //   })
        //   const resData = res.data.records || []

        //   const result = []
        //   for (const item of resData) {
        //     if (item.category === 1) {
        //       const sonResponse = await getList({
        //         current: 1,
        //         size: 9999,
        //         parentId: item.id
        //       })
        //       const sonListData = sonResponse.data.records || []
        //       if (sonListData.length === 0) {
        //         item.leaf = true
        //       } else {
        //         const sonRes = []
        //         for (const items of sonListData) {
        //           if (items.category === 1) {
        //             sonRes.push(items)
        //           }
        //         }
        //         if (sonRes.length === 0) {
        //           item.leaf = true
        //         } else {
        //           item.leaf = false
        //         }
        //       }
        //       result.push(item)
        //     }
        //   }
        //   resolve(result)
        // }
      },
      pageParams: {},
      temp: {
        parentIdArr: [],
        parentId: ''
      },
      rules: {
        // parentIdArr: [
        //   { required: true, message: '请选择所属父资源', trigger: 'change' }
        // ]
      }
    }
  },
  watch: {
    // 表单内容体
    temp: {
      handler: function(val, oldVal) {
      },
      deep: true
    }
  },
  created() {
    // 列表传过来的数据
    this.pageParams = this.drawerCurrent.params.pageParams || {}
    this.getList()
  },
  mounted() {

  },
  methods: {
    async getList() {
      const res = await getList()
      const resData = res.data || []
      this.treeList = resData
    },
    handleChange(val) {
    },
    // 提交表单
    submitForm() {
      return this.$refs['dataForm'].validate()
    },
    // 获取表单数据
    getFormData() {
      const parentId = (this.temp.parentIdArr)[(this.temp.parentIdArr).length - 1]
      return {
        parentId,
        id: this.pageParams.id
      }
    }
  }
}
</script>

<style rel="stylesheet/scss" lang="scss" scoped>
</style>
